#include "stdafx.h"
#include <MyControls/FootageProperty.h>
#include <MyControls/PropertySPtrValue.h>
#include <MyControls/StdProperties.h>
#include <MyControls/EnumProperty.h>
#include <MyControls/Resource.h>
#include <xtd/string>

namespace My {

class ExtentAsString : public ReadAccess<String> {
public:
	ExtentAsString(boost::shared_ptr< ReadAccess<Extent> > pGet)
		: m_pGet(pGet) { }
public:
	virtual bool Accept(const EditableObject & obj) const
		{ return m_pGet->Accept(obj); }
	virtual bool GetValue(const EditableObject & obj, String & value) const {
		Extent tmp;
		if (!m_pGet->GetValue(obj, tmp))
			return false;
		value = (xtd::string(tmp.sx) + " x " + tmp.sy);
		return true;
	}
public:
	boost::shared_ptr< ReadAccess<Extent> > m_pGet;
};

inline boost::shared_ptr< ReadAccess<String> > ToString(boost::shared_ptr< ReadAccess<Extent> > pGet)
	{ return boost::shared_ptr< ReadAccess<String> >(new ExtentAsString(pGet)); }

template <>
EnumItem<icache::deinterlace_fields> EnumTypeControl<icache::deinterlace_fields>::Items[] =
{
	{"Upper First", icache::fields_upper_first},
	{"Lower First", icache::fields_lower_first}
};

SPECIALIZE_ENUM_TYPE_CONTROL(icache::deinterlace_fields)

template <>
EnumItem<icache::deinterlace_method> EnumTypeControl<icache::deinterlace_method>::Items[] =
{
	{"Duplicate", icache::method_duplicate},
	{"Interpolate", icache::method_interpolate}
};

SPECIALIZE_ENUM_TYPE_CONTROL(icache::deinterlace_method)

Property<FootageSPtr>::Property(bool expanded)
	: StructProperty<FootageSPtr>(expanded) 
{
}

void Property<FootageSPtr>::Init()
{
	(* this)[MY_FOOTAGE_DURATION] = &Create(My::ReadOnly(* this, &Footage::size));
	(* this)[MY_FOOTAGE_DESCRIPTION] = &Create(My::ReadOnly(* this, &Footage::description));
	(* this)[MY_FOOTAGE_ALPHA] = &Create(My::ReadOnly(* this, &Footage::alpha_channel));
	(* this)[MY_FOOTAGE_STILL] = &Create(My::ReadOnly(* this, &Footage::still));
	(* this)[MY_FOOTAGE_DIMENSIONS] = &Create(My::ReadOnly(ToString(My::Read(* this, &Footage::dim))));
	(* this)[MY_FOOTAGE_FRAMERATE] = &Create(My::ReadOnly(* this, &Footage::fps));
	static GroupProperty<bool> Deinterlaced;
	(* this)[MY_FOOTAGE_DEINTERLACED] = &Deinterlaced.Read(My::ReadOnly(* this, &Footage::deinterlaced));//.Read(&Footage::deinterlaced);
	ReadBoolSPtr pVisible = My::Read(* this, &Footage::deinterlaced);
	Deinterlaced[MY_FOOTAGE_DEINTERLACED_FIELD] = &Create(My::ReadWrite<icache::deinterlace_fields>(My::Read(* this, &Footage::get_deinterlace_fields), My::Write(* this, &Footage::set_deinterlace_fields))).Visible(pVisible);
	Deinterlaced[MY_FOOTAGE_DEINTERLACED_METHOD] = &Create(My::ReadWrite<icache::deinterlace_method>(My::Read(* this, &Footage::get_deinterlace_method), My::Write(* this, &Footage::set_deinterlace_method))).Visible(pVisible);
}

} //namespace My
